var Rectangle = function(x1,y1,x2,y2){
	this.x1 = x1;
	this.y1 = y1;
	this.x2 = x2;
	this.y2 = y2;
}

Rectangle.prototype = {
	copyPosition : function(element){
		this.x1 = element.position().left;
		this.y1 = element.position().top;
		this.x2 = this.x1 + element.width();
		this.y2 = this.y1 + element.height();
	},
	copyOffset : function(element){
		this.x1 = element.offset().left;
		this.y1 = element.offset().top;
		this.x2 = this.x1 + element.width();
		this.y2 = this.y1 + element.height();
	},
	copy : function(rectangle){
		this.x1 = rectangle.x1;
		this.y1 = rectangle.y1;
		this.x2 = rectangle.x2;
		this.y2 = rectangle.y2;
	},
	copyVector2 : function(vector){
		this.x1 = vector.x;
		this.x2 = vector.x;
		this.y1 = vector.y;
		this.y2 = vector.y;
	},	
	clone : function(){
		return new Rectangle(this.x1, this.y1, this.x2, this.y2);
	},
	set : function(x1, y1, x2, y2){
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	},	
	width : function(){
		return Math.abs(this.x2 - this.x1);
	},
	height : function(){
		return Math.abs(this.y2 - this.y1);
	},
	toString : function(){
		return "[" + this.x1 + ", " + this.y1 + ", " + this.x2 + ", " + this.y2 +"]";
	},
	intersects : function( rectangle ){
		var a = this;
		var b = rectangle;
		return a.x1 < b.x2 
			&& a.x2 > b.x1 
			&& a.y1 < b.y2 
			&& a.y2 > b.y1;
	}
}
Rectangle._temp = [];
Rectangle.pop = function(){
	if(Rectangle._temp.length == 0){
		Rectangle._temp.push( new Rectangle(0,0,0,0) );
	}
	return Rectangle._temp.shift();
}
Rectangle.push = function(rect){
	Rectangle._temp.push( rect );
}
